/**
 * Copyright 2019 Inc.
 **/
package com.myz.demo;

import feign.Feign;
import feign.gson.GsonDecoder;
import feign.ribbon.LoadBalancingTarget;
import feign.ribbon.RibbonClient;

import java.util.List;

/**
 * JacksonEncoder依赖:被用于JSON格式的API
 * <dependency>
 * <groupId>com.netflix.feign</groupId>
 * <artifactId>feign-ribbon</artifactId>
 * <version>8.18.0</version>
 * </dependency>
 *
 * @author maoyz0621 on 19-7-11
 * @version: v1.0
 */
public class RibbonFeign {

    /**
     * 使用RibbonClient和LoadBalancingTarget
     *
     * @param args
     */
    public static void main(String... args) {
        GitHub github = Feign.builder()
                .client(RibbonClient.create())
                .decoder(new GsonDecoder())
                .target(GitHub.class, "https://api.github.com");

        GitHub target = Feign.builder()
                .decoder(new GsonDecoder())
                .target(LoadBalancingTarget.create(GitHub.class, "https://api.github.com"));


        List<Contributor> contributors = github.contributors("OpenFeign", "feign");
        for (Contributor contributor : contributors) {
            System.out.println(contributor.login + " (" + contributor.contributions + ")");
        }

        List<Contributor> _contributors = target.contributors("OpenFeign", "feign");
        for (Contributor contributor : _contributors) {
            System.out.println(contributor.login + " (" + contributor.contributions + ")");
        }
    }
}